<?
// Database Connection
$dbname = 'tcntrans_main';
$dbhost = 'localhost';
$dbuser = 'tcntrans';
$dbpass = 'hJV65VUX';
$db = mysql_connect($dbhost,$dbuser,$dbpass);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>New document</title>
<meta name="generator" content="TSW WebCoder">
</head>

<body>
<h1>Updating Links</h1>
<?
$row = 1;
$handle = fopen("StudentUpdates1.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    //echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    
    $levelID  = $data[0];
    $linkID  = $data[1];
    $title   = $data[7];
    $desc    = $data[8];
    $link    = $data[9];
    $output  = 'LevelID: '.$levelID.'<br>';
    $output .= 'LinkID:  '.$linkID.'<br>';
    $output .= 'Title: '.$title.'<br>';
    $output .= 'Description: '.$desc.'<br>';
    $output .= 'Link: '.$link.'<hr>';
    //echo $output;
    
    // Update database
    // First, let's see if this LinkID even exists
    $sql1 = "SELECT LinkID from transLinks WHERE LinkID = '$linkID'";
    $result1 = mysql_db_query($dbname,$sql1); 
    
    if (mysql_num_rows($result1)>0) {
	    $sql = "UPDATE transLinks SET
	    			Title = '$title',
	    			LinkDescription = '$desc',
	    			Link  = '$link',
	    			Status = '1',
	    			ErrorCode = '',
	    			ErrorLevel = ''
	    		WHERE
	    			LinkID = $linkID";
	    $result = mysql_db_query($dbname,$sql); 
	    echo 'Updating LinkID: '.$linkID.'<br />';
	} else {
		echo $output;
	}	  			
    
}
fclose($handle);
?>


</body>
</html>